package com.znow.admin.system.security.model.convert;

import com.znow.admin.dao.entity.sys.SysPermissionEntity;
import com.znow.admin.system.security.model.vo.component.ComponentVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 系统角色权限与权限转换
 *
 * @author Administrator
 * @date 2022/11/02
 */
@Mapper
public interface ComponentConvert {

    ComponentConvert INSTANCE = Mappers.getMapper(ComponentConvert.class);

    /**
     * 组件dto
     *
     * @param entity 实体
     * @return {@link ComponentVO}
     */
    @Mappings({
            @Mapping(source = "permissionUrl", target = "path"),
            @Mapping(source = "componentPath", target = "component"),
            @Mapping(source = "componentName", target = "name"),
            @Mapping(source = "permissionIcon", target = "meta.icon"),
            @Mapping(source = "permissionName", target = "meta.title"),
            @Mapping(source = "permissionId", target = "permissionId"),
            @Mapping(source = "parentId", target = "parentId"),
    })
    ComponentVO toComponentDTO(SysPermissionEntity entity);

    /**
     * 组件dtolist
     *
     * @param entities 实体
     * @return {@link List}<{@link ComponentVO}>
     */
    List<ComponentVO> toComponentDTOList(List<SysPermissionEntity> entities);

}
